﻿using System;
using System.Data;
using System.Configuration;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.Configuration;
using System.Data.SqlClient;

/// <summary>
/// Summary description for StoredProcedures
/// </summary>
/// 
namespace ShowMeTellMeData
{
  public class StoredProcedures
  {
    public StoredProcedures()
    {
      //
      // TODO: Add constructor logic here
      //
    }

    //Returns datatable containing one random question

    public static DataTable GetRandomQuestion()
    {
      DataTable question = new DataTable();
      SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["CrossHairV2ConnectionString"].ToString());

      try
      {
        SqlCommand cmd = new SqlCommand("S1_Get_Random_Question_Text", connection);
        cmd.CommandType = CommandType.StoredProcedure;

        connection.Open();
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        adapter.Fill(question);
        connection.Close();
      }
      catch
      {
        connection.Close();
      }
      return question;
    }

    //Returns datatable containin one answer given the question text

    public static DataTable GetAnswer(string questionText)
    {
      DataTable answer = new DataTable();
      SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["CrossHairV2ConnectionString"].ToString());
      SqlParameter SP1 = new SqlParameter();

      try
      {
        SqlCommand cmd = new SqlCommand("s1_get_answer_from_question_text", connection);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.Add("@questionText", SqlDbType.NVarChar).Value = questionText;

        connection.Open();
        SqlDataAdapter adapter = new SqlDataAdapter(cmd);
        adapter.Fill(answer);
        connection.Close();
      }
      catch
      {
        connection.Close();
      }
      return answer;

    }

  }
}